import { PlanService } from './../../../service/plan/plan.service';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Slides } from '@ionic/angular';
import { PlanInfo } from 'src/app/model/PlanInfo';

@Component({
  selector: 'app-all-plan',
  templateUrl: './all-plan.page.html',
  styleUrls: ['./all-plan.page.scss']
})
export class AllPlanPage implements OnInit {
  //当前页面的下标
  pageIndex: number = 1;
  pageContent: string;
  //头部标签数据集合
  pageSlides: string[] = ['全部计划', '未完成', '已完成'];
  plans:PlanInfo[];
  @ViewChild(Slides) slides: Slides;
  constructor(private planService: PlanService) {}

  ngOnInit() {
    this.setPageContent();
  }
  //头部标签的点击事件
  onSlideClick(index) {
    this.pageIndex = index;
    this.slides.slideTo(index);
    this.setPageContent();
  }

  setPageContent() {
    this.pageContent = this.pageSlides[this.pageIndex];
    console.log("setPageContent:"+this.pageIndex.toString());
    this.getPlan(this.pageIndex.toString());
  }
  //内容slides的幻灯片转换结束时发出
  slideTransitionEnd() {
    this.slides.getActiveIndex().then(index => {
      console.log(index);
      this.pageIndex = index;
      this.setPageContent();
    });
  }
  getPlan(state: string) {
    this.planService.getPlan(state, res => {
      console.log('app-plan getPlan()');
      this.plans=res.data;
    });
  }
}
